home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 80 / CD Actual 80 Julio-Agosto 2003.iso / Linux / LinuxGazette / lg / issue39 / rogers_example05a.c < prev    next >
Encoding:
C/C++ Source or Header  |  2002-08-14  |  656 b   |  43 lines

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. /*
  5.  
  6.     This program is written to demonstrate the <stdlib.h> library.
  7.  
  8.     This program will demonstrate integer math
  9.  
  10.     Written by James M. Rogers
  11.  
  12.     17 March 1999
  13.  
  14.     Released to the Public Domain on this date.
  15.  
  16. */
  17.  
  18. main(){
  19.  
  20.     int a, b;
  21.     long int c, d;
  22.     div_t x;
  23.     ldiv_t y;
  24.  
  25.     a = 10;
  26.     b = 3;
  27.  
  28.     x = div(a, b);
  29.     printf(" div (%d, %d) returns a quotient of %d and a remainder of %d\n", a, b, x.quot, x.rem);
  30.  
  31.     c = 1000000;
  32.     d = 337;
  33.  
  34.     y = ldiv(c, d);
  35.     printf(" div (%d, %d) returns a quotient of %d and a remainder of %d\n", c, d, y.quot, y.rem);
  36.  
  37.     a = -100;
  38.  
  39.     b = abs(a);
  40.     printf("The absolute value of %d is %d\n", a, b);
  41.  
  42. }
  43.